package com.leetcode;

import com.leetcode.common.TreeNode;

/**
 * 面试题 04.06. 后继者
 *
 * @author fy
 * @date 2022-05-16 22:33
 */
public class Solution04_06_1 {

    public TreeNode inorderSuccessor(TreeNode root, TreeNode p) {
        int target = p.val;
        TreeNode cur = root;
        TreeNode ans = null;
        while (cur != null){
            if (cur.val > target){
                ans = cur;
                cur = cur.left;
            }
            else{
                cur = cur.right;
            }
        }
        return ans;
    }

}
